package org.demon.springtest.design.singleton;

/**
 * @author demon
 * @version 1.0.0
 */
public class Singleton {

    private Singleton() {
        System.out.println("Singleton is create");
    }

    private static Singleton instance = null;

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null)
                    instance = new Singleton();
            }
        }
        return instance;
    }


    public static void main(String[] args) {
//        for (int i = 0; i < 10; i++) {
//            Singleton singleton = getInstance();
//            System.out.println(singleton.toString());
//        }

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                Singleton singleton = getInstance();
                System.out.println(singleton.toString());
            }).start();
        }
    }
}
